/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.service.processor.login;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.customer.core.domain.Customer;
import info.peigen.hotpot.business.customer.core.domain.operator.CustomerOperator;
import info.peigen.hotpot.business.customer.core.service.processor.base.AbstractCustomerServiceProcessor;
import info.peigen.hotpot.business.customer.facade.order.login.CustomerLoginOrder;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;

/**
 * <b>(CustomerLoginProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/8/30
 */
@SuppressWarnings("rawtypes")
@Component
public class CustomerLoginProcessor extends AbstractCustomerServiceProcessor implements Processor {

    @Override
    public Integer level() {
        return 50;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        Customer           customer       = (Customer) serviceContext.getDomain();
        CustomerOperator   masterOperator = customer.getMasterOperator();
        CustomerLoginOrder order          = (CustomerLoginOrder) serviceContext.getOrder();
        if (StrUtil.equals(order.getLoginName(), masterOperator.getLoginName())) {
            masterOperator.getActiveInfo().setLastLoginTime(DateUtil.date())
                    .setLastLoginIp(order.getLoginIp());
        }
    }
}
